using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class SupplierMap : EntityTypeConfiguration<Supplier>
	{
		public SupplierMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.CodeValue)
				.HasMaxLength(15);
				
			this.Property(t => t.NameValue)
				.HasMaxLength(200);
				
			this.Property(t => t.ContactPerson)
				.HasMaxLength(50);
				
			this.Property(t => t.NPWP)
				.HasMaxLength(50);
				
			this.Property(t => t.Phone)
				.HasMaxLength(50);
				
			this.Property(t => t.Mobile)
				.HasMaxLength(50);
				
			this.Property(t => t.Fax)
				.HasMaxLength(50);
				
			this.Property(t => t.BankAccount)
				.HasMaxLength(50);
				
			this.Property(t => t.BankAccountName)
				.HasMaxLength(50);
				
			this.Property(t => t.BankBranch)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("Suppliers");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.CodeValue).HasColumnName("CodeValue");
			this.Property(t => t.NameValue).HasColumnName("NameValue");
			this.Property(t => t.ContactPerson).HasColumnName("ContactPerson");
			this.Property(t => t.JoinDate).HasColumnName("JoinDate");
			this.Property(t => t.NPWP).HasColumnName("NPWP");
			this.Property(t => t.TermOp).HasColumnName("TermOp");
			this.Property(t => t.Phone).HasColumnName("Phone");
			this.Property(t => t.Mobile).HasColumnName("Mobile");
			this.Property(t => t.Fax).HasColumnName("Fax");
			this.Property(t => t.VAT).HasColumnName("VAT");
			this.Property(t => t.PPH23).HasColumnName("PPH23");
			this.Property(t => t.PPH24).HasColumnName("PPH24");
			this.Property(t => t.InCatalogue).HasColumnName("InCatalogue");
			this.Property(t => t.BankAccount).HasColumnName("BankAccount");
			this.Property(t => t.BankAccountName).HasColumnName("BankAccountName");
			this.Property(t => t.BankBranch).HasColumnName("BankBranch");
			this.Property(t => t.BankId).HasColumnName("BankId");
			this.Property(t => t.RecordStatus).HasColumnName("RecordStatus");
			this.Property(t => t.SupplierTypeId).HasColumnName("SupplierTypeId");

			// Relationships
			this.HasOptional(t => t.Bank)
				.WithMany(t => t.Suppliers)
				.HasForeignKey(d => d.BankId);
				
			this.HasOptional(t => t.RefSupplierType)
				.WithMany(t => t.Suppliers)
				.HasForeignKey(d => d.SupplierTypeId);
				
		}
	}
}

